package com.ccq.repository.impl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.ccq.entity.BlogTitle;
import com.ccq.entity.Comment;
import com.ccq.repository.BlogTitleRepository;

@Repository
public class BlogTitleRepositoryImpl implements BlogTitleRepository {
	
	
	@Autowired
	private SessionFactory sessionFactory;

	private Session getCurrentSession() {
		return this.sessionFactory.openSession();
	}

	@Override
	public BlogTitle load(Integer id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BlogTitle get(Integer id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<BlogTitle> findAll() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void persist(BlogTitle entity) {
		// TODO Auto-generated method stub

	}

	@Override
	public Integer save(BlogTitle entity) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void saveOrUpdate(BlogTitle entity) {
		// TODO Auto-generated method stub

	}

	@Override
	public void delete(Integer id) {
		// TODO Auto-generated method stub

	}

	@Override
	public void flush() {
		// TODO Auto-generated method stub

	}

	@Override
	public List<BlogTitle> blogPage() {
		Session session = getCurrentSession();
		String hql ="FROM BlogTitle";
		List list = session.createQuery(hql).list();
		return list;
	}

	@Override
	public void add(BlogTitle blog) {
		
		Session session = getCurrentSession();
	    
	    session.save(blog);
	    blog.getBlogDetail().setBlogTitle(blog);
	    session.save(blog.getBlogDetail());
		
	}

	@Override
	public Comment addComment(Comment c) {
		Session session = getCurrentSession();
		Integer save = (Integer)session.save(c);
		
		return c;
	}

}
